import Cookies from 'js-cookie'

const TokenKey = 'YL_DATACENTER_TOKEN'
const RefreshTokenKey = 'YL_DATACENTER_REFRESHTOKEN'
const UserIdKey = 'YL_DATACENTER_USERID'
const TokenExpTimeKey = 'YL_DATACENTER_TOKENEXPTIME'
const config = {
  development: {
    expires: 7
  },
  test: {
    domain: '.964yx.com',
    expires: 7
  },
  production: {
    domain: '.964yx.com',
    expires: 7
  },
  release: {
    domain: '.964yx.com',
    expires: 7
  }
}

export function getToken() {
  return [Cookies.get(TokenKey), Cookies.get(RefreshTokenKey), Cookies.get(UserIdKey), Cookies.get(TokenExpTimeKey)]
}

export function setToken(Token, RefreshToken, UserId, TokenExpTime) {
  Cookies.set(TokenKey, Token, config[process.env.NODE_ENV])
  Cookies.set(RefreshTokenKey, RefreshToken, config[process.env.NODE_ENV])
  Cookies.set(UserIdKey, UserId, config[process.env.NODE_ENV])
  Cookies.set(TokenExpTimeKey, TokenExpTime, config[process.env.NODE_ENV])
}

export function removeToken() {
  Cookies.remove(TokenKey, config[process.env.NODE_ENV])
  Cookies.remove(RefreshTokenKey, config[process.env.NODE_ENV])
  Cookies.remove(UserIdKey, config[process.env.NODE_ENV])
  Cookies.remove(TokenExpTimeKey, config[process.env.NODE_ENV])
}
